<include file="header" />
<link rel="stylesheet" href="/assets/bower_components/sweetalert/lib/sweet-alert.css?v={BEESCRM:$time}">
</head>
<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/carreserve/images/load-bee.png">
    </div>
	<div class="head clearfix">
		<a href="javascript:history.go(-1);" class="iconfont icon-zuo pull-left"></a>
		<span class="head-name pull-left">乘车信息</span>
		<a href="/base/carReserve/index/car_id/{BEESCRM:$car_id}" class="pull-left text-right iconfont icon-shouye"></a>
	</div>
	<div class="block-space">
		<div class="contain">
			<div class="ticket">
				<p class="strong">{BEESCRM:$data.start_address} <span class="iconfont icon-arrowgo"></span>{BEESCRM:$data.end_address}</p>
				<p>发车时间：{BEESCRM:$data.send_time|date="Y-m-d H:i",###}</p>
				<p>发车地点：{BEESCRM:$data.start_address}</p>
			</div>
			<div class="wave-rown"></div>
			<div class="block-space">
				<div class="tb-mode margin-b">
					<p class="tb-cell">数量： <span class="price">1</span></p>
					<p class="tb-cell text-right">总价：<span class="price">￥{BEESCRM:$data.price}元 / 人</span></p>
				</div>
			</div>
		</div>
		<div class="lists">
			<div class="form-list tb-mode">
				 <p class="tb-cell field">预约姓名</p>
				 <p class="tb-cell"><input class="information" id="username" value="{BEESCRM:$data.username}"/></p>
			</div>
			<div class="form-list tb-mode">
				 <p class="tb-cell field">联系方式</p>
				 <p class="tb-cell"><input class="information" id="mobile" value="{BEESCRM:$data.mobile}"/></p>
			</div>
			<div class="form-list tb-mode">
				 <p class="tb-cell field">身份证号</p>
				 <p class="tb-cell"><input class="information" id="card_num" value="{BEESCRM:$data.card_num}"/></p>
			</div>
		</div>
		<input type="hidden" value="{BEESCRM:$data.line_id}" id="line_id">
		<input type="hidden" value="{BEESCRM:$car_id}" id="car_id">
		<input type="hidden" value="{BEESCRM:$order_id}" id="order_id">
		<!--<div class="lists text-center"><span>+</span> 继续添加</div>-->
	</div>
	<div class="fixed-box">
		<a href="javascript:void(0);" class="btn">立即支付</a>
		<div class="rule clearfix">
			<p class="rule-title">—— 包车进度 ——</p>
			<div class="step">
				<p class="iconfont icon-1 text-green"></p>
				<p>选择路线</p>
			</div>
			<div class="step">
				<p class="iconfont icon-2 text-green"></p>
				<p>预约支付</p>
			</div>
			<div class="step">
				<p class="iconfont icon-3"></p>
				<p>等待成团</p>
			</div>
			<div class="step">
				<p class="iconfont icon-4"></p>
				<p>包车成功</p>
			</div>
		</div>
	</div>
</div>
<script src="/assets/base/carreserve/js/jquery-2.1.0.min.js"></script>
<script src="/assets/base/carreserve/js/jq.utils.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/assets/bower_components/sweetalert/lib/sweet-alert.min.js"></script>
<script>
	$(function(){
		var fixed_h = $('.fixed-box').height();
		$('.wraper').css("marginBottom",fixed_h);
	});

	$(window).load(function(){
		$('.load').hide();
	});

	//提交支付
	$('.btn').on('click',function(){
		var line_id = $("#line_id").val();
		var username = $("#username").val();
		var mobile = $("#mobile").val();
		var card_num = $("#card_num").val();
		var car_id = $('#car_id').val();
		var order_id = $('#order_id').val();
		if(!line_id){
			$.alert('error','参数错误');return false;
		}

		if(!username){
			$.alert('error','姓名不能为空');return false;
		}

		if(!mobile){
			$.alert('error','联系方式不能为空');return false;
		}

		if(!card_num){
			$.alert('error','身份证号码不能为空');return false;
		}

		$.ajax({
			'url': "/base/carReserve/recharge/car_id/"+car_id,
			'data': {'line_id':line_id,'username':username,'mobile':mobile,'card_num':card_num,'order_id':order_id},
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') {
					var wxpay = $.parseJSON(data.wxpay);
					var order_id = data.order_id;
					pay(wxpay,order_id);
				}else{
					$.alert('error',data.message);
					return false;
				}
			}
		});

		//微支付
		function pay(wxpay,order_id){
			if (typeof WeixinJSBridge == "undefined"){
				if( document.addEventListener ){
					document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
				}else if (document.attachEvent){
					document.attachEvent('WeixinJSBridgeReady', jsApiCall);
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
				}
			}else{
				WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						wxpay,
						function(res){
							WeixinJSBridge.log(res.err_msg);
							if(res.err_msg == "get_brand_wcpay_request:ok"){
								paySuccess(order_id);
							}else if(res.err_msg == "get_brand_wcpay_request:cancel"){
								$.alert('error','付款已取消');
								return false;
							}else{
								$.alert('error','调用微支付失败');
								return false;
							}
						}
				);
			}
		}

		function paySuccess(order_id){
			location.href = "/base/carReserve/detail/car_id/"+car_id+'/order_id/'+order_id;
		}
	});
</script>
</body>
</html>